#ifndef LIBCHECK
#define LIBCHECK
#include <stdlib.h>
#endif

#ifndef STRCHECK
#define STRCHECK
#include <string.h>
#endif

#ifndef MCHECK
#define MCHECK
#include "mallocCheck.h"
#endif

char** tokenize(char* string, const char* token){
  if(string == NULL) return NULL;
  int i = 0;
  char** parsed = (char**) malloc((i+1)*sizeof(char*));
  mallocCheck(parsed);
  parsed[i] = strtok(string, token);
  if(parsed[i] == NULL){
    free(parsed);
    return NULL;
  }
  i++;
  char** tempParsed = (char**) malloc((i+1)*sizeof(char*));
  mallocCheck(tempParsed);
  memmove(tempParsed, parsed, i*sizeof(char*));
  free(parsed);
  parsed = tempParsed;

  while((parsed[i] = strtok(NULL, token)) != NULL){
    i++;
    tempParsed = (char**) malloc((i+1)*sizeof(char*));
    mallocCheck(tempParsed);
    memmove(tempParsed, parsed, i*sizeof(char*));
    free(parsed);
    parsed = tempParsed;
  }
 
  return parsed;
  


}
